var productId;
window.onload = function () {
    productId = getQuery("id");
    init();
};

//初始化经理页面
async function init() {
    var productInfo = await ajaxGet("/product/findById",{
        id:productId
    });

    $("productImg").src = "/html/img/"+productInfo.imgPath;
    $("productName").innerHTML = productInfo.productName;
    $("price").value = productInfo.productPrice;
    $("productAddress").innerHTML = productInfo.productAddress;
    $("productTime").innerHTML = productInfo.productTime;
    $("productNum").innerHTML = productInfo.num;
    $("statusInfo").innerHTML = productInfo.status;
    if (productInfo.status == "上架"){
        $("status").value = "下架";
    }else if (productInfo.status == "下架"){
        $("status").value = "上架";
    }
}

//修改状态
async function status1() {
    let info = await ajaxGet("/product/update",{
        productId:productId,
        status:$("status").value
    });
    if(info == "ok"){
        location.href = "/html/leader/findProduct.html?id="+productId
    }else {
        alert("修改失败请重试")
    }
}

//修改单价
async function updatePrice() {
    let info = await ajaxGet("/product/update",{
        productId:productId,
        price:$("price").value
    });
    if(info == "ok"){
        location.href = "/html/leader/index.html"
    }else {
        alert("修改失败请重试")
    }
}

//返回主页
function back() {
    location.href = "/html/leader/index.html"
}